/*
 * @Author: atony2099
 * @Date: 2019-02-14 14:21:49
 * @Last Modified by:   atony2099
 * @Last Modified time: 2019-02-14 14:21:49
 */

'use strict';

module.exports = {
  toError(code, message, detail) {
    this.status = code || 500;
    const error_msg =
      this.status === 500 && this.app.config.env === 'pro'
        ? 'internal server error'
        : message;
    this.body = { error_msg };
    if (detail) {
      this.body.error_detail = detail;
    }
  },

  toSuccess(info, error_msg, error_code = 0) {
    this.body = {
      error_code,
    };
    if (info) {
      this.body.data = info;
    }
    if (error_msg) {
      this.body.error_msg = error_msg;
    }
  },
};
